/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fhv.itb.ec.fruitshop;

import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Malcolm
 */
@Stateful
public class FruitShopBean implements FruitShopLocal {

    @PersistenceContext(unitName = "FruitShop-ejbPU")
    private EntityManager em;

    public FruitShopBean() {
        if (em == null) {
            System.out.println("EM is not OK");
        }

    }

    public static void main(String[] args) {
        System.out.println("Testing database");
        FruitShopBean fsb = new FruitShopBean();
        fsb.createShop();
    }

    public Long createShop() {
        FruitShopEntity fse = new FruitShopEntity();

        if (em == null) {
            System.out.println("EM is not OK");
        } else {
            em.persist(fse);
            return fse.getId();
        }

        return null;
    }

    public void persist(FruitShopEntity ojb) {
        em.persist(ojb);
    }

    public Fruit getFruit(int id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void putFruit(Fruit fruit) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
